{{ $eventsPath := (printf "data/%s/events/events.toml" $.Language.Lang (dateFormat "2006" now)) }}

{{ $eventsData := "" }}
{{ if (fileExists $eventsPath) -}}
  {{ $data := index .Site.Data $.Language.Lang }}
  {{ $eventsData = $data }}
{{ else }}
  {{ $dataDefaultLanguage := index .Site.Data .Sites.First.Language.Lang }}
  {{ $eventsData = $dataDefaultLanguage }}
{{ end }}

{{ with $eventsData }}
  {{ $eventsCounter := 0 }}
    {{ range (sort .events "year" "asc") }}
      {{ if le $eventsCounter 6 }}
        {{ range (sort .events "startDate" "asc") }}
          {{ if ge (dateFormat "20060102" .endDate) (dateFormat "20060102" now) }}
            <p>
              <span class="txtdate">{{ dateFormat "2006-01-02" .startDate }} - {{ dateFormat "2006-01-02" .endDate }}</span>
              <br />
              <a href="{{ if (fileExists $eventsPath) -}}{{ .Site.BaseURL | relLangURL }}{{ else }}{{ $.Site.BaseURL }}{{- end }}events/#{{ .id }}">
                {{ .name }}
                <br />
                {{ if or (.city) (.country) }}({{end}}{{ if .city }}{{ .city }},{{ end }} {{ if .country }}{{ .country }}{{ end }}{{ if or (.city) (.country) }}){{end}}
              </a>
            </p>
            {{ $eventsCounter = add $eventsCounter 1 }}
          {{ end }}
        {{ end }}
      {{ end }}
    {{ end }}
{{ end }}
